package com.webchat.admin.controller;


import com.webchat.admin.config.CallbackEncryptKeyConfig;
import com.webchat.admin.service.CallBackService;
import com.webchat.common.bean.APIResponseBean;
import com.webchat.common.bean.APIResponseBeanUtil;
import com.webchat.common.util.AESEncryptUtil;
import com.webchat.common.util.JsonUtil;
import com.webchat.common.util.ThreadPoolExecutorUtil;
import com.webchat.domain.dto.payment.CallBackRequestBodyDTO;
import com.webchat.domain.dto.payment.PaymentCallbackEncryptBody;
import com.webchat.domain.dto.payment.PaymentResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/api-service/callback")
public class CallBackController {

    @Autowired
    private CallBackService baseCallBackService;

    /**
     * webchat pay 支付结果回调
     *
     * @return
     */
    @PostMapping("/webchat-pay")
    public APIResponseBean<Boolean> webpayCallBack(@RequestBody PaymentCallbackEncryptBody paymentCallbackEncryptBody) {

        /**
         *  callback 的处理应该是异步的，支付平台不关心这里的处理结果，只关心ACK（有没有成功收到callback请求）
         */
        ThreadPoolExecutorUtil.execute(() -> {
            baseCallBackService.webchatPaymentCallBack(paymentCallbackEncryptBody);
        });
        return APIResponseBeanUtil.success(true);
    }
}
